<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目名称">
          <el-input v-model="queryParam.qry_projectname" placeholder="请输入名称关键词" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item label="项目级别">
          <el-select v-model="projectlevelList" multiple placeholder="请选择项目级别" style="width:190px">
            <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目经理">
          <el-input v-model="queryParam.qry_projectmanager" placeholder="工号或姓名" @keyup.enter.native="doQuery"> </el-input>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" :refMainTable="$refs.mainTable" currentModuleTableCode="mpmProject/main" :startColumn="3" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" :isDisplayExport="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="doExportExcel" v-hasPermission="['sys:excel:export']">导出</el-button>
      </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="40px" fixed="left" :selectable="doDisableCheckBox"></el-table-column>
        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
        <el-table-column prop="deptname" label="所属部门" width="110px" sortable="custom" sort-by="deptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectcode" label="项目编号" width="150px" sortable="custom" sort-by="projectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="300px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanager" label="项目经理" width="80px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectlevel" label="项目级别" width="80px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="80px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag :type="changeStateType(scope.row.state)">
              {{ scope.row.dispstate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="dispprojectstate" label="项目阶段" width="115px" sortable="custom" sort-by="projectstate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="bidcycle" label="项目周期(天)" width="105px" sortable="custom" sort-by="bidcycle" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="planstartdate" label="计划开始日期" width="105px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="planenddate" label="计划结束日期" width="105px" sortable="custom" sort-by="planenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="actualenddate" label="实际结项日期" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="participatemoney" label="可参与金额（万元）" width="150px" sortable="custom"  sort-by="participatemoney" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="projectendmoney" label="结项金额（万元）" width="135px" sortable="custom"  sort-by="projectendmoney" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <!-- <el-table-column prop="currentmilepost" label="当前里程碑及任务" width="200px" sortable="custom" sort-by="currentmilepost"
          align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="currentmilepoststate" label="当前里程碑及任务状态" width="150px" sortable="custom"
          sort-by="currentmilepoststate" align="center" header-align="center" :show-overflow-tooltip="true">
        </el-table-column> -->
        <el-table-column prop="sponsor" label="Sponsor" width="75px" sortable="custom" sort-by="sponsor" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="owner" label="Owner" width="75px" sortable="custom" sort-by="owner" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="decisionusername" label="决策组人员" width="150px" sortable="custom" sort-by="decisionusername" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="background" label="项目背景概述" width="240px" sortable="custom" sort-by="background" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="importance" label="项目概述" width="200px" sortable="custom" sort-by="importance" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="productrange" label="涉及产品范围" width="200px" sortable="custom" sort-by="productrange" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="target" label="项目目标" width="200px" sortable="custom" sort-by="target" align="left" header-align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="summary" label="总体策划" width="200px" sortable="custom" sort-by="summary" align="left" header-align="left" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="orgname" label="所属组织" width="200px" sortable="custom" sort-by="orgname" align="left"
          header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="docdate" label="单据日期" width="170px" sortable="custom" sort-by="docdate" align="center"
          header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="docno" label="单据编号" width="150px" sortable="custom" sort-by="docno" align="center"
          header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="latestphase" label="最新阶段" width="80px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="scope.row.state !== 0 && scope.row.state !== 2">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看 </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import { checkPermission } from '@tapui/utils/permission'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
export default {
  name: 'mpmProject',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      projectlevelList: [],
      description: '项目立项-列表查询',
      urlPrefix: '/mpm/projectpolymerization/',
      url: {
        queryCodeList: '/mpm/projectpolymerization/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'mpmproject.submitdate',
        sord: 'desc'
      }
    }
  },
  methods: {
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      // 判断双击打开是查看还是编辑
      if (row.state === 0 || row.state === 2 || this.$store.getters.user.adminlevel === 9) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      if (this.projectlevelList) {
        param.qry_projectlevel = this.projectlevelList.join(',')
      }
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.fromProject = '1'
      return filterObjectNull(param)
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : state === 2 ? 'danger' : state === 9 ? 'success' : ''
    }
  }
}
</script>

<style scoped></style>
